package com.example.chao.myphotosearch.widget;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.chao.myphotosearch.Listener.StartSearchActivityListener;
import com.example.chao.myphotosearch.R;
import com.example.chao.myphotosearch.dao.RecommendContent;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chao on 2016/4/6.
 */
public class LinearCardView extends LinearLayout {
    @Bind(R.id.recomend_img1)
    SimpleDraweeView recomendImg1;
    @Bind(R.id.recommend_title1)
    TextView recommendTitle1;
    @Bind(R.id.recommend_content1)
    TextView recommendContent1;
    @Bind(R.id.recommend_cardview1)
    CardView recommendCardview1;
    @Bind(R.id.recomend_img2)
    SimpleDraweeView recomendImg2;
    @Bind(R.id.recommend_title2)
    TextView recommendTitle2;
    @Bind(R.id.recommend_content2)
    TextView recommendContent2;
    @Bind(R.id.recommend_cardview2)
    CardView recommendCardview2;
    public LinearCardView(Context context) {
        this(context, null);
    }

    public LinearCardView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LinearCardView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(context).inflate(R.layout.itemview_recommend, this, true);
        ButterKnife.bind(this);
    }

    public void setCardView(List<RecommendContent> recommends,int position) {
        int mPosition = 2*position;
        setContent(recomendImg1, recommendTitle1, recommendContent1, recommends.get(mPosition));
        setContent(recomendImg2, recommendTitle2, recommendContent2, recommends.get(mPosition + 1));
        recommendCardview1.setOnClickListener(new StartSearchActivityListener(recommends.get(mPosition)));
        recommendCardview2.setOnClickListener(new StartSearchActivityListener(recommends.get(mPosition + 1)));
    }
    private void setContent(SimpleDraweeView draweeView, TextView title, TextView content, RecommendContent recommendContent) {
        draweeView.setImageURI(Uri.parse(recommendContent.getImgUrl()));
        title.setText(recommendContent.getTitle());
        content.setText(recommendContent.getContent());
    }


}
